import ChiVoxSDK from 'chivox';
import Config from './config';

import $ from 'jquery';
import '../css/chivox-example.css';

let mode = ChiVoxSDK.MODE.HTML5;
//let mode = ChiVoxSDK.MODE.FLASH;

let __PRTL = {
    QID: "PAPER-946273-QT-614396",
    Examples: [{
            "answer": 2,
            "text": "As we all know, different countries have their own special body language. If you don't know the differences, maybe you will misunderstand them. Jack is a good case in point. One day, he was travelling on a train to a small town in India. Next to him was a young man, who was a native. Jack was a talkative person and soon they became familiar to each other. \"Are you from India?\" asked Jack, the young man smiled and shook his head. So where are you from? Jack asked again. To Jack's surprise, the young man said that he was indeed a native. But why did you shake your head? Jack was a little confused. Luckily, the young man was very smart, he suddenly became aware that Jack must misunderstand him because he knew a little body language in different countries when expressing agree or disagree. After explaining to Jack, Jack's confusion had been melted. With time going on, Jack wanted to go to the restroom, he asked the young man, \"Is it the right way to the restroom\", and the young man nodded his head this time. \"Oh, I understand, it is on the opposite side.\""
        }, {
            "answer": 1,
            "text": "As we all know, different countries have different body language, if you don't know it, you will misunderstand them. Jack is a case in point, one day he was on the train to a small town of India and next to him is an India young man. Jack is a talkative person, so they get familiar with each other quickly. Jack asked the young man whether he is from Indian, then the young man shook his head. So where are you from? Jack asked him, the young man said he was indeed a native, jack was confused about it, you are a native, but why you shook your head. Fortunately, the young man is a very smart and he knew something about body language he thought Jack was misunderstood his meaning, he explained it to Jack, and at last Jack made clear of it. With time going on, Jack went to a restaurant, he asked the waiter: is this the right way to the rest room? The waiter nodded his head, and then Jack knew that the opposite way is the right way of it."
        }, {
            "answer": 1,
            "text": "As we all know different countries have their own special body languages. If you don't know the difference, you may misunderstand them. Jack is a typical case in point. One day he was on a small train in India. He met a young Indian man .Because Jack was an active talker, they became familiar with each other very soon. Then Jack asked the young man whether he came from India or not. The young Indian smiled and shook his head. So Jack continued to ask the young man the same question. The young man said：\"You are a complete idiot!\" Jack was so confused. The Indian was smarted and explained the meaning of shaking head in India. Shaking head means agreement while nodding head means disagreement. After that, Jack's confusion melted. Later Jack was going to a restaurant. He asked the young man: \"Is it the right way?\" The young man nodded his head. Jack understood that the restaurant was on the opposite side."
        }, {
            "answer": 1,
            "text": "Different countries have different body languages. If you have no idea on this issue, you may get yourself in big trouble while travelling in foreign countries. Jack exemplifies the point when he travelled in India. One day during his journey in India, Jack encountered a native young man, and they soon became familiar with each other. Jack asked the young man whether he was native. The young man smiled and shook his head, and Jack felt so confused and continued to ask him where he was from. Suddenly, the young man became aware that Jack knew little about the body language in India and then explained the difference to Jack. Therefore, Jack's confuse melted away. Later, Jack asked the young man whether it was the right way to the restaurant, and the young man nodded this time. Jack clearly knew it meant not."
        }, {
            "answer": 1,
            "text": "Different countries have different body language. If people don't know about it, misunderstanding may happen. Jack travelled in India, confused about nodding head and snaking head. In India, nodding head means \"No\", but shaking head means \"Yes\". So, misunderstanding happened between Jack and his friend during their talk with body language."
        }, {
            "answer": 1,
            "text": "Different countries have their different body languages. If you don't know, you will misunderstand them. Jack's example is very typical of this phenomenon. Because of Jack's little knowing of body language, he made a lot of embarrassment in public."
        }, {
            "answer": 1,
            "text": "Different countries have their own body languages. One day, Jack was on a trip, he asked a young man if he was an Indian. The young man shook his head. Then, he asked where he come from. To Jack's surprise, the young man said he was an Indian. Later, the same misunderstanding happened again. In India, shaking head means yes while nodding head means no. so it is important to know the body language in different countries."
        }, {
            "answer": 1,
            "text": "Different countries have different body language. If people don't know, misunderstanding may happen. Once, Jack travelled in India, was confused about nodding head and shaking head. Nodding head means \"No\" in India, but shaking head means \"Yes\". There's no doubt that misunderstanding happened between Jack and his friends during their talk with body language."
        }, {
            "answer": 1,
            "text": "Different countries have different body language. We should get some knowledge before we travel there. If we don't, we may get misunderstood. Once, Jack travelled in India. There were some thing happened to him. Nodding head means disagreement in India. Meanwhile, shaking hand means agreement. First, Jack misunderstood his new friend followed the rule like Jack's body language, to nod the head means \"yes\". However, Jack misunderstood him again. Think about this matter, don't do the thing again."
        }, {
            "answer": 1,
            "text": "I used to give money to the homeless. When I was poor, I started it. One day I saw a homeless person. And again I saw a man standing in the corner. Something inside me told me that \"help the guy\". I gave all money to him. He was moved deeply and said I haven't seen my mother for a long time."
        }, {
            "answer": 1,
            "text": "Different countries have different body language. If he don't get some knowledge before we travel there, we may get misunderstood. Like things happened to Jack, who travelled in India. In India, nodding head means disagreement, while shaking head means agreement. At first, Jack misunderstood his new friend as he didn't know shaking head means \"yes\", after a while, when another question occurred, the India friend followed the rule like Jack's body language, to nod the head means \"yes\", but Jack misunderstood him again, thinking this time, nodding head also means \"no\", going to the opposite direction."
        }, {
            "answer": 1,
            "text": "Different countries have different body languages. If we don't know, we will get misunderstood Jack felt confused in India as he couldn't know what's the true meaning of nodding head and shaking head."
        }, {
            "answer": 0,
            "text": "Know the different countries. One day jack was plo on the tree. One suad tow in Indian, big million to each other. The group man smiled. He was indid was tale. Luckily the young man was smart. Because of the new, jack wanted to go to the rostile."
        }, {
            "answer": 0,
            "text": "Different countries have different bodies language. In the world, jack is good case of point. Jack is not come from Indian. Shake his head."
        }, {
            "answer": 0,
            "text": "Different country has its language. Once, jack travelled on a tran to a small town in India. Jack had a problem communicating with the young man. Jack misunderstood him."
        }, {
            "answer": 0,
            "text": "They don't know the difference. Jack in a small town in india. When jack in the train, he explain the meaning of \"shake head\" to a young man. He want to do west want and invite the young man. But he didn't go with him."
        }, {
            "answer": 0,
            "text": "all the constructions has their body language. Jack had a talk with an Indian."
        }, {
            "answer": 0,
            "text": "Jack a good a young man who jack a person. To jack's surpise, the man said. Jack wanted to go to the."
        }, {
            "answer": 0,
            "text": "Jack travel by a train to a small town in India. A young man sit near him. Jack ask the young man \"are you a Indian.\" But the man shake the hand. Jack asked again. The young man said that the same. In different countries have different means."
        }, {
            "answer": 0,
            "text": "different countries have different languages. The young man asked the way to the restaurant. The young man was very smart. Jack wants to go to the restaurant. The restaurant is on the opposite."
        }, {
            "answer": 0,
            "text": "India to the person return."
        }, {
            "answer": 0,
            "text": "different country has different language. One day, jack visited Inda. He saw a young man in the train. Then, he asked the man if he comes from inda. The young man smiled and shaked his heads. Then he said to jack. He is very smart. he knows jack's meaning."
        }, {
            "answer": 0,
            "text": "Many countries have different languages. One day, jack was traveling to India, jack talked with a man who was Indian. Jack wanted to go to a restaurant and asked a young man the way to the restaurant. He shaked his head."
        }, {
            "answer": 0,
            "text": "Jack is a good case is point. He was traveling Indian. Jack wanted to go to the restaurant and asked the young man is that right way to the restaurant."
        }, {
            "answer": 0,
            "text": "Different body languages are used in different countries. It we don't know about that we may be misunderstood. In indana, nodding head means \"No\", while shaking head means ges. Because of this misunderstanding happened between jack and his indana friends. During their conversation"
        }, {
            "answer": 0,
            "text": "Different country has different body language. One day, jack travel to Indian, there he met a local young man knew he was new here. From jack's exprience, we can learn that we should know each countrys body language."
        }, {
            "answer": 0,
            "text": "Different countries have different body languages. Jack is traveling in Indian: \"are you from Indian\" Jack asked the young man. The young man is very smart."
        }, {
            "answer": 0,
            "text": "As we know, different countries have different body lunages, if you don't know it can help you understabd. Jack is a good point. One day he was travelling in the country. Jack is tallest man. Young man said:\" when are you from?\" young man surprised and he know they have different languages. He want to go to the restaurant. So he said: \"is it the right way to restaurant? The young man."
        }, {
            "answer": 0,
            "text": "Different countries have different body languagre. Jake made mistakes one day. Jake asked a young man in India, but he couldn't understand the meaning of the man. Jake wented to go to restaurant, he asked a young man the way, but he also couldn't understand and got the wrong way."
        }, {
            "answer": 0,
            "text": "countries has different language. If you don't know the difference. One day traveling on the train. Are you from Indian? Asked jack. to jack surprise, why did you shake your head. The young man smart. didn't understand him body language smild. Jack asked the young man. \"is this the right way to the restaurant."
        }, {
            "answer": 0,
            "text": "Different country have their own special body language. Jack travel in Indian. Are you from in asked Jake. The man shake his head. \"where are you from\" Jake asked again. The mon shakes his head means he is from Indian. But Jack didn't understand."
        }, {
            "answer": 0,
            "text": "Different countries have different language. Jack asked the guy: \" are you come from Japan?\" the young manis very polite and come from india. Sometimes. Jack doesn't understand the young man's languages. There are many interesting thing between them."
        }, {
            "answer": 0,
            "text": "Every different country has different body language. Maybe you will understand it,. One day, he was traveling in the train to small town. Next to him, Jack a talk to person town young. Jack is surprise. The young man idiena. Jack a little lucky. Jake must make mistakes because he know a litte body language. Jake asked the young man is it the right way to restaurant."
        }, {
            "answer": 0,
            "text": "different countries has their own special body language. Jack met an Indian. He asked the Indian whether he was from india. The man shaked his hand. Then jack asked where he was from. The man asked he was from Indian. Jack was confused. But the man was smart. he knew that jack was confused. But the man was smart. he knew that jack was misunderstand. In india, shake hand was agree."
        }, {
            "answer": 0,
            "text": "As we all also, different culture reperense from different country. Jack is good at sports. \"are you from Indian\", asked jack. young man silmed. Young man very smart."
        }, {
            "answer": 0,
            "text": "Different countries have their special body languages. Young man ask for something. But the young man's restrant ask way body language what jack couldn't understand."
        }, {
            "answer": 0,
            "text": "differ country have own body language. The young man comes from Indian. jack was a top student. The young man was very smart. shack head express \"ok\". Jack wanted go to the restaurant. Nod head express \"No\"."
        }, {
            "answer": 0,
            "text": "different countries have different language if you can't understand. You will in trouble. The man called Jackwent to Indian."
        }, {
            "answer": 0,
            "text": "Different country has different body language. Become it, Jack make a mistake with a man from Indina."
        }, {
            "answer": 0,
            "text": "different countries has different body language. Jack traveling on a train to small town in India. Young man shake head."
        }, {
            "answer": 0,
            "text": "We all know different countries has different laugegations. One day, jack was on the tree. A young man call susan from indiya. He asked jack \" where are you from\","
        }, {
            "answer": 0,
            "text": "a people from India met jack. They spoke used indiou. He considered jack comes from India and followed Jack."
        }, {
            "answer": 0,
            "text": "Jack is a good kid, he is a top student. Jack confusion."
        }, {
            "answer": 0,
            "text": "As we all know, a body language is different in different country. Jack is a good cas. He travelled in India. Jack was a talktive person and talked with a Indian. A body language in different countries represents different meanings."
        }, {
            "answer": 0,
            "text": "different country has different languages. He missed a young man, they comes from different countries. And they can connection fluently with each other."
        },

        {
            "answer": 0,
            "text": "jack the young man."
        }, {
            "answer": 0,
            "text": "Different countries have different languages. Two people from different countries said with each other. The young man was very smart."
        }, {
            "answer": 0,
            "text": "Different countries have the same language. Jack is a good person. The young men is familiar with jack and ask jack: are you from Indian? Jack want go to the restaurant, the young nab us undeed. Jack ask the young man: is the the restaurant."
        }, {
            "answer": 0,
            "text": "One day, jack travel in india, and he visited a young man. Jack said: are you from India?\" the young man said \"yes.\" The young man was very smart. Jack wanted to go to the restaurount."
        }, {
            "answer": 0,
            "text": "as we all, jack is a kindful man."
        }, {
            "answer": 0,
            "text": "Different people have different language, the boy tell the man the right way."
        }, {
            "answer": 0,
            "text": "Every country has the different languages jack was travel on the trains, jack talk with him. The man said he from indio."
        }, {
            "answer": 0,
            "text": "A small town in Indian. Jack is a good young man show his head. Jack is a talk person to jacks surprised, luckily, the Youngman, this time going off. He asked the young man, is it the right way to restourint."
        }, {
            "answer": 0,
            "text": "Different countries have different languages, jack is a good, \"are you from Indian?\" asked jack, the young man was very smart, jack wanted to go to the, jack must understand the young man."
        }, {
            "answer": 0,
            "text": "Jack was traveling to India. He met a people. He asked him if he is a local person. The man said yes, but."
        }, {
            "answer": 0,
            "text": "Different countries have different languages. Jack is a good case, He was traveling in the Indian. The young man asked jack: \"where are you come from?\" the young man said that he was indeed. After explaining to jack, jack asked the young man."
        }, {
            "answer": 0,
            "text": "As we all know, different countries have different languages. Once, jack was traveling on the train, he met a young man, but the man can't speak the language that jack said. When jack asked questions, the young man just smiled and shook his head. But he was smart. At last, he let jack know his meaning."
        }, {
            "answer": 0,
            "text": "As we all know, different countries have didn't body language. If you don't know the difference, we may not understand then Jack went to Indian. He met a young man. He asked him if he is Indian. The young man smiled and shake his head. But he is really the mative person. Shaking head sightly means. Yes, and shaking head heavily means no."
        }, {
            "answer": 0,
            "text": "Don't know understand on the familiar each the young didn't countries understand traveling small town India. Jack person familiar young man smile he was indeed luckily, smart, knew. Jack travel a small town in indan the person there are very familiar with he."
        }, {
            "answer": 0,
            "text": "different countries has different languages. Jack come from Indian. The young man be famileyed with Jack. The young man very smart. Jike want to go to restround. Ask the young man right or left. The young man says oppside."
        }, {
            "answer": 0,
            "text": "Jake was traveling on the train. He met a young man. He asked the man that whether he is from India. The young man shook his head. However, the young man is indeed from India. Jack asked the young man. \"Is it the way to the restaurant?\" body languages are very useful."
        }, {
            "answer": 0,
            "text": "body language. Jack show hand the young girl know a little about other country's body languages. Agree or disagree."
        }, {
            "answer": 0,
            "text": "Traveling small town Indian, different countries has its special body language, if you don't know them, \" are you from Indian \" you will misunderstanding, the young man smile, the young man was very smart, with tome going on, restaurant if you don't Jane ask the young man, Jane traveling in the trip in the small town in Indian , Jane is a talkative person, Jake asked the young man are you from Indian, to jack's surprise, the young man smiled and showed his head. Was a little confused the young man was very smart disagree."
        }, {
            "answer": 0,
            "text": "As we all know different countries is having special body language. Jack is good at. Jack is traveling to Indian, are you go to Indian a young man asked. The young man is very smart, the young man is Indian."
        }, {
            "answer": 0,
            "text": "Different countries have different body languages, if you don't know them. You my mistake other. Jack was traveling in the train. Next to him is a young man. Jack was traveling in the train, next to him is a young man. Jack is talkative so he chatted with the man, the man knows that the differences between different countries and then they had a chatted about the body languages."
        }, {
            "answer": 0,
            "text": "if you don't know the differences study."
        }, {
            "answer": 0,
            "text": "As we all know, different countries have there own body languages. Jale is a good case. Jake was a talkive person. Are you from Indian, Jake asked. He young man shake his hand. The young man very smart. He ask the young man is that the right way to the restant?"
        }, {
            "answer": 0,
            "text": "as we all know, different understand. Jake one day understand next to him take live are you find fifty, young man said you are nice, smart. They are talking about the Jake and young man."
        }, {
            "answer": 0,
            "text": "Every country's body language is different Jack is a good case in this point."
        }, {
            "answer": 0,
            "text": "Different countries have different body languages. Jack is a good example of this case."
        }, {
            "answer": 0,
            "text": "Different country have different body languages. Jack ask different country, people the same problems, but their body languages are different, so, jack is understand."
        }, {
            "answer": 0,
            "text": "Different countries have own special body languages. Maybe you can't understand if you don't know. Jack traveling on a train, soon, he is familiar with a young man who next to him, jack asked him . \"are you from india\". The man shocked his head. Jack was surprised . the man is smart. He knows different body language. He said: \"I'm from india\", then jack know the meaning about the body language. He asked the man. The man nod his head. Jack knowed the right way is the opposite one."
        }, {
            "answer": 0,
            "text": "Special body language at least, she can speak. Different countries have different body languages."
        }, {
            "answer": 0,
            "text": "One day, he was travelling in intim. Are you from in taily? The young man was very smart. different countries have different cultures."
        }, {
            "answer": 0,
            "text": "Jack is friendly on the train. Next to him is a young man. Jack asked \" are you from india?\" the young man shoked his head, but he is from india?"
        }, {
            "answer": 0,
            "text": "Jack a top person. Jack wanted to go to the restaurant. Jack asked the young man."
        }
    ],
};

$(".currentWord").html(__PRTL.Examples[0].text);

let rank = parseFloat($('#rank').val());
let precision = parseFloat($('#precision').val());
let getScoreRank = (score) => {
    return score;
};

let sdk = new ChiVoxSDK({
    appKey: Config.appKey,
    mode: mode,
    sigurl: "/token",
    data: {
        audioUrl: "",
        duration: 60000,
        serverParams: {
            coreType: "en.prtl.exam",
            refText: {
                qid: __PRTL.QID,
                lm: __PRTL.Examples
            },
            rank: rank,
            precision: precision,
            userId: "chivox tester",
        }
    },

    onInit: (errno, err) => {
        console.info('[ onInit ]:', errno, err);
    },

    onError: (err) => {
        console.error('[ onError ]:', err);
    },

    onBeforeRecord: () => {
        rank = parseFloat($('#rank').val());
        precision = parseFloat($('#precision').val());

        sdk.options.data.serverParams.rank = rank;
        sdk.options.data.serverParams.precision = precision;

        $("#scoreResult .overall").empty();
        $("#scoreResult .pron").empty();
        $("#scoreResult .integrity").empty();
        $("#scoreResult .fluency").empty();
        $("#scoreResult .tips").empty();
        $("#scoreResult .rhythm").empty();
    },

    onScore: (data) => {
        console.info(data);
        $("#scoreResult .overall").html(data.result.overall);
        $("#scoreResult .pron").html(getScoreRank(data.result.pron));
        $("#scoreResult .integrity").html(getScoreRank(data.result.integrity));
        $("#scoreResult .fluency").html(getScoreRank(data.result.fluency));
        $("#scoreResult .rhythm").html(getScoreRank(data.result.rhythm));
        $("#scoreResult .tips").html(data.result.tips);
    },

    onScoreError: (errorType) => { //评分失败的显示 "TIMEOUT", "NO_DATA", ErrorID
        var errorObj = ChiVoxSDK.StatusCode.get(errorType, "cn");
        alert(errorObj.feedback);
    }
});
